package poiSeleniumTests;

import com.thoughtworks.selenium.*;
import org.junit.Before;
import org.junit.Test;

public class SearchSeleniumTest extends SeleneseTestCase {

	@Before
	public void setUp() throws Exception {
		setUp("http://localhost:8080/POISystem/", "*chrome");
	}

	@Test
	public void testSearchSystem() throws Exception {
		selenium.open("/POISystem/");
		selenium.click("link=Search for POI");
		selenium.waitForPageToLoad("30000");
		selenium.type("j_id_jsp_1003048030_1:j_id_jsp_1003048030_5", "a");
		selenium.type("j_id_jsp_1003048030_1:j_id_jsp_1003048030_13", "1");
		selenium.select("j_id_jsp_1003048030_1:homePOI", "label=Home");
		selenium.click("j_id_jsp_1003048030_1:j_id_jsp_1003048030_17");
		selenium.waitForPageToLoad("30000");
		assertNotEquals(selenium.getHtmlSource().indexOf("<h3>Finished!</h3>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>16</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Kvartz</td>"), -1);
		
		selenium.type("j_id_jsp_1003048030_1:j_id_jsp_1003048030_5", "");
		selenium.select("j_id_jsp_1003048030_1:poiType", "label=Store");
		selenium.type("j_id_jsp_1003048030_1:j_id_jsp_1003048030_13", "2");
		selenium.click("j_id_jsp_1003048030_1:j_id_jsp_1003048030_17");
		selenium.waitForPageToLoad("30000");
		assertNotEquals(selenium.getHtmlSource().indexOf("<h3>Finished!</h3>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>1</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Depo't</td>"), -1);

		selenium.type("j_id_jsp_1003048030_1:j_id_jsp_1003048030_13", "12");
		selenium.click("j_id_jsp_1003048030_1:j_id_jsp_1003048030_17");
		selenium.waitForPageToLoad("30000");
		assertNotEquals(selenium.getHtmlSource().indexOf("<h3>Finished!</h3>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>1</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Depo't</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>2</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Maydan</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>3</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Metro</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>4</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Epicenter</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>5</td>"), -1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Ecvator</td>"), -1);

		selenium.select("j_id_jsp_1003048030_1:homePOI", "label=Autobus station");
		selenium.select("j_id_jsp_1003048030_1:poiType", "label=Recreation");
		selenium.type("j_id_jsp_1003048030_1:j_id_jsp_1003048030_13", "1");
		selenium.click("j_id_jsp_1003048030_1:j_id_jsp_1003048030_17");
		selenium.waitForPageToLoad("30000");
		assertNotEquals(selenium.getHtmlSource().indexOf("<h3>Nothing is found!</h3>"), -1);
	}
}
